<script>
import balance from "./balance.vue";

export default {
  name: "myinfo",
  data() {
    return {
      form: {
        id: '',
        staff_remark: '',
        fileList: []
      },
      action:  this.$baseUrl + '/api/upload/file',
      fileList: [],
      userInfo: {},
      balance: 0
    }
  },
  onLoad() {
    const userInfo = this.$store.state.userInfo || {}
    if (userInfo.id) {
      this.$api.getUserInfo(userInfo.id).then(res => {
        this.userInfo = res
        this.$store.commit('SET_USERINFO', res)
      })
    }
  },
  methods: {
    submit() {
      let balance = parseFloat(this.balance)
      let total_balance = parseFloat(this.userInfo.balance)
      if (balance > total_balance) {
        uni.showToast({
          title: '提现金额不能大于可提现金额',
          icon: 'none',
          duration: 2000
        })
        return
      }
      this.$api.createBalance({
        staff_id: this.$store.state.userInfo.id,
        desc: '提现',
        amount: -balance,
        type: 2,
        status: -1
      }).then(() => {
        uni.showToast({
          title: '已提交',
          icon: 'none',
          duration: 2000
        })
        setTimeout(() => {
          uni.navigateBack()
        })
      })
    },
    logout() {
      uni.showModal({
        title: '提示',
        content: '确定退出登录？',
        success: (res) => {
          if (res.confirm) {
            this.$store.commit('SET_USERINFO', {})
            uni.navigateTo({
              url: '/pages/user/login'
            })
          }
        }
      })
    }
  }
}
</script>

<template>
  <div class="myinfo">
    <div class="form-box">
      <u-form :model="form" ref="uForm" label-position="top">
        <u-form-item label="可提现金额">
          {{ userInfo.balance }}
        </u-form-item>
        <u-form-item label="金额"><u-input v-model="balance" type="number" /></u-form-item>

      </u-form>
    </div>
    <div class="button button-primary" style="margin: 30rpx 0;width: 100%" @click="submit" >提交</div>
  </div>
</template>

<style lang="scss">
.myinfo {
  height: 100%;
  background-color: #F5F7FA;
  padding: 20rpx;
  .primary-button {
    margin-top: 15px;
    display: flex;
    align-items: center;
    justify-content: center;
    height: 41px;
    line-height: 41px;
    font-size: 16px;
    color: #fff;
    background-color: #2aac34;
    border-radius: 5px;
    box-sizing: border-box;
  }
  .form-box {
    border-radius: 10px;
    background-color: #FFFFFF;
    padding: 20rpx;
  }
}
</style>
